package com.popwindow;

import android.content.Context;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.ButterKnife;


/**
 * 消息浮动框Popup
 * Created by oushuhua on 2017/2/28.
 */

public class FloatingPopup  {

   /* private JReceiverPojo mJReceiverPojo;
    private TextView mInternalTitle, mInternalContent;
    private CountDownTimer countDownTimer;

    public FloatingPopup(Context context, JReceiverPojo mReceiverPojo) {
        this.mJReceiverPojo = mReceiverPojo;
        mContext = context;
        if (mJReceiverPojo != null) {
            initView();
        }

    }

    @Override
    public void setPopwindow(PopupWindow pop) {
        mPopwindows = pop;
        autoClosePop();
    }


    @Override
    public View getView() {
        return super.getView();
    }

    private void initView() {
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.internal_message_popup, new LinearLayout(mContext), false);
        setListener();
    }

    private void setListener() {
        View root = View.inflate(getContext(), R.layout.internal_message_popup, null);
        mInternalTitle = ButterKnife.findById(root, R.id.internal_title);
        mInternalContent = ButterKnife.findById(root, R.id.internal_content);
        RelativeLayout mRelativeLayout = ButterKnife.findById(root, R.id.internal_layout);
        OTeventLayout mLinearLayout = ButterKnife.findById(root, R.id.internal_linearlayout);
        mInternalTitle.setText("mJReceiverPojo.getTitle()");
        mInternalContent.setText("mJReceiverPojo.getAlert()");
        mLinearLayout.setMonitorListener(new OTeventLayout.OTeventLayoutListener() {
            @Override
            public void popup_dismiss() {
                dismiss();
                Log.d("oushuhua", "popup_dismiss");
            }

            @Override
            public void getClick() {
                Log.d("oushuhua", "popup_dismiss");
                if (mJReceiverPojo != null) {
                    //KuServiceJumpUtil.startActivity(getContext(), mJReceiverPojo.getToAction());
                } else {
                   *//* Intent it = new Intent(getContext(), SystemMessageListActivity.class);
                    it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    getContext().startActivity(it);*//*
                }
                dismiss();
            }
        });
    }

    private void autoClosePop() {
        if (countDownTimer == null)
            countDownTimer = new CountDownTimer(5000, 1000) {
                @Override
                public void onTick(long l) {
                    //倒计时每秒的回调
                }

                @Override
                public void onFinish() {
                    //倒计时结束
                    if (mPopwindows.isShowing())
                        dismiss();
                }
            };

        countDownTimer.start();
    }

    private void closeDownTimer() {
        if (countDownTimer != null)
            countDownTimer.cancel();
    }


  *//*  @Override
    public void showAtLocation(View parent, int gravity, int x, int y) {
        super.showAtLocation(parent, gravity, x, y);
        autoClosePop();
    }*//*


    public void dismiss() {
        super.mPopwindows.dismiss();
        closeDownTimer();
        Log.d("oushuhua", "dismiss调用");
    }*/
}
